package com.gexin.common.log;

import java.util.HashMap;
import java.util.Map;
import com.jfinal.kit.HttpKit;
import com.jfinal.kit.PropKit;
import com.jfinal.log.Log;

/**
 * 日志上报的kit 类
 * @author 肖得明  
 *
 */
public class GeXinLogKit {
	private static final Log  log =  Log.getLog(GeXinLogKit.class);
	public static enum LogType{
		Error,Notify
	};
	
	/**
	 * 是否开启日志
	 */
	public final static boolean  Log_EnablePush= PropKit.getBoolean("Log_EnablePush");
	/**
	 * token 
	 */
	public final static String  Log_Token= "token=" + PropKit.get("Log_Token");
	/**
	 * 提交地址
	 */
	public final static String  Log_PostAddress= PropKit.get("Log_PostAddress");
	
	public static  String host_ip=GeXinIpKit.INTERNET_IP;//本机IP
	public static  String api_host="null";//接口地址
	
	public static void postLog(LogType t ,  String msg,String data){
		if(!Log_EnablePush){
			return ;
		}
		
		Map<String, String>  map  =new HashMap<String, String>();
		map.put("type", t.name());
		map.put("message", msg);
		map.put("data", data);
		map.put("clientIp", host_ip);
		try {
			HttpKit.post(Log_PostAddress, map, Log_Token);
		} catch (Exception e) {
			log.info("请求错误");
		}
	}
}

